GBML manual / Maths

ceil

value rounded UP to a whole number, toward POSITIVE INFINITY, and handed back as a real - 1.1 becomes 2, and -1.1 becomes -1.

Syntax

ceil(value) -> real

Arguments

NameType
valuereal

Returns

real

Description

value rounded UP to a whole number - toward POSITIVE INFINITY - and handed back as a real. 1.1 becomes 2, and -1.1 becomes -1.

ceil and int_ceil round the same way and differ only in what they hand back. ceil returns a real, so it goes straight back into more real maths. int_ceil returns an int. This is the same rule as floor and round: no prefix means a real, and int_ means a whole number.

Example

var tile_size = 8.0;
var covered = ceil(37 / tile_size) * tile_size;

37 pixels needs 5 whole 8px tiles to cover it, and five tiles span 40 pixels, so covered is 40.0.

Write 8.0, not 8. When both sides of a / are whole numbers, the answer is a whole number too: 37 / 8 is 4, with the fraction thrown away before ceil ever sees it, and ceil(4) is just 4. A number with a decimal point makes the division keep its fraction, so ceil has something left to round up.

Cost

One call into the Game Boy Advance module's own round-up call for fixed-point numbers, then back to a real. It costs what int_ceil costs.

On the GBA

The same rounding as int_ceil (the GBA module’s own fixed-point round-up function), but the answer is a real with nothing after the point, so it can go straight back into real maths. Use int_ceil instead when the result must be an int. The division rule still comes first: ceil(37 / 8) is 4, because 37 / 8 with two whole numbers has already lost its fraction before ceil sees it - write ceil(37 / 8.0) to get 5.

See also: floorroundint_ceilint_partint_round